<template>
    <view class="order_details">
        <dl>
            <dt>
                <image :src="info.shoplogo" mode=""></image>
            </dt>
            <dd>
                <p>{{ info.shopname }}</p>
                <text>Order ID: {{ info.orderid }}</text>
            </dd>
        </dl>
        <view class="order_info">
            <!-- 待使用 -->
            <view class="order_code" v-if="info.state == '1'">
                <!-- <image :src="info.verification_url" mode=""></image> -->
                <qrcode
                    text="核销二维码"
                    :content="info.verification_code + ' ' + info.orderno"
                />
                <view class="code">{{ info.verification_code }}</view>
                <p>Verification QR code</p>
            </view>
            <!-- up -->
            <view class="info_header">
                <p>Payment Details</p>
                <!-- 已评价ss -->
                <text v-if="info.state == '3'">Rated</text>
                <!-- 待评价 -->
                <text v-if="info.state == '2'" style="color: #fc721a"
                    >Awaiting Evaluation</text
                >
                <!-- 待使用 -->
                <text v-if="info.state == '1'" style="color: #fc721a"
                    >To be used</text
                >
            </view>
            <ul v-if="info">
                <li>
                    <text>Original price</text>
                    <text>{{ info.origin_money }}Egp</text>
                </li>
                <li>
                    <text>Discount price</text>
                    <text>{{ info.discount_money }}Egp</text>
                </li>
                <li v-if="info.coupon_money">
                    <text>Coupon deduction price</text>
                    <text>{{ info.coupon_money }}Egp</text>
                </li>
                <li>
                    <text>Final payment</text>
                    <text style="font-weight: bold"
                        >{{ info.pay_money }}Egp</text
                    >
                </li>
                <li>
                    <text>Payment Time</text>
                    <text>{{ info.ctime }}</text>
                </li>
            </ul>
        </view>
        <view class="order_products">
            <p class="products_title">Products</p>
            <ul>
                <li v-for="(item, index) in itemList" :key="index">
                    <dl>
                        <dt v-if="item.imgurl">
                            <image
                                :src="item.imgurl.split(',')[0]"
                                mode=""
                            ></image>
                        </dt>
                        <dd>
                            <view class="products_item header">
                                <text>{{ item.name }}</text>
                                <text>{{ item.payMoney }}Egp</text>
                                <!-- <text v-if="item.state=='2'" style="color:#FC721A">Awaiting Evaluation</text> -->
                            </view>
                            <view class="products_item">
                                <text>Quantity: {{ item.numbers }}</text>
                                <text class="line">{{ item.payMoney }}Egp</text>
                            </view>
                            <view class="products_item">
                                <text>Classic pasta with a rich ...</text>
                                <text style="color: #fc721a"
                                    >-{{ item.discount }}%</text
                                >
                            </view>
                            <view class="products_item">
                                <text>Discount</text>
                                <text>{{ item.actualPrice }}Epg</text>
                            </view>
                            <view class="products_item">
                                <text>Discounted Price</text>
                                <text></text>
                            </view>
                        </dd>
                    </dl>
                </li>
            </ul>
        </view>
        <view class="" style="padding: 0 32rpx">
            <Comment
                :commentList="[info]"
                v-if="info && info.review_score"
            ></Comment>
        </view>
        <view class="footer">
            <!-- v-if="info.state=='1'" -->
            <view
                class="footer_btn"
                v-if="info.state == '1'"
                style="background: #ececeb; color: #000"
                @click.stop="handleCancel"
            >
                Cancel Order
            </view>
            <!-- 待评价 -->
            <view
                class="footer_btn"
                v-if="info.state == '2'"
                @click.stop="handleEval"
            >
                To Review
            </view>
            <!-- up -->
            <!-- 待退款 -->
            <!-- <view
                class="footer_btn"
                v-if="info.refund == '1'"
                @click.stop="handleRefund"
            >
                Refund
            </view> -->
        </view>
    </view>
</template>

<script>
import Comment from "@/pages/index/components/comment";
import qrcode from "../../components/qrcode/qrcode";

import {
    getMyOrderDetail,
    getOrderCancel,
    getRequestRefund,
} from "@/lib/business.js";
import { RECOED_DESC } from "../../../constant";
export default {
    data() {
        return {
            orderid: "",
            info: {},
            itemList: [],
        };
    },
    components: {
        Comment,
        qrcode,
    },
    onLoad(options) {
        this.orderid = options.orderid;
        this.handleInfo();
    },
    methods: {
        handleInfo() {
            getMyOrderDetail({
                orderid: this.orderid,
            }).then((res) => {
                this.info = res.data;
                this.itemList = res.data.item_list || [];
            });
        },
        handleEval() {
            uni.navigateTo({
                url: `./rate?orderid=${this.orderid}&shopname=${this.info.shopname}&shoplogo=${this.info.shoplogo}`,
            });
        },
        handleCancel() {
            let _this = this;
            uni.showModal({
                title: "Cancel Order",
                content: "Are you sure you want to cancel the order?",
                success: (res) => {
                    if (res.confirm) {
                        console.log("用户点击确定");
                        getOrderCancel({
                            orderid: _this.orderid,
                        }).then((resp) => {
                            uni.showToast({
                                title: "Cancel Success",
                                icon: "none",
                            });
                            _this.handleInfo();
                        });
                    } else if (res.cancel) {
                        console.log("用户点击取消");
                    }
                },
            });
        },
        // 去退款
        handleRefund() {
            let _this = this;
            uni.showModal({
                title: "Request a refund",
                content: "Are you sure you want to apply for a refund?",
                success: (res) => {
                    if (res.confirm) {
                        getRequestRefund({
                            orderid: _this.orderid,
                        }).then((resp) => {
                            uni.showToast({
                                title: "Please wait for review",
                                icon: "none",
                            });
                            _this.handleInfo();
                        });
                    } else if (res.cancel) {
                        console.log("用户点击取消");
                    }
                },
            });
        },
    },
};
</script>

<style lang="scss" scoped>
.order_details {
    padding: 32rpx 0;
    padding-bottom: 140rpx;

    > dl {
        display: flex;
        align-items: center;
        padding: 0 32rpx;

        dt {
            width: 128rpx;
            height: 128rpx;

            overflow: hidden;

            image {
                width: 100%;
                height: 100%;
                border-radius: 50%;
                background: #eeeeee;
            }
        }

        dd {
            margin-left: 20rpx;

            p {
                font-size: 44rpx;
                font-weight: bold;
                color: #1c120d;
            }

            text {
                font-size: 32rpx;
                color: #9e6b47;
                display: block;
                padding-top: 8rpx;
            }
        }
    }

    .order_info {
        padding: 0 32rpx;

        .order_code {
            margin: 0 auto;
            text-align: center;
            margin-top: 40rpx;
            .code {
                font-weight: 600;
                font-size: 36rpx;
                color: #000000;
                margin-top: 40rpx;
            }
            image {
                width: 200rpx;
                height: 200rpx;
                background: #eee;
                border-radius: 16rpx;
            }

            p {
                font-size: 32rpx;
                color: #666666;
            }
        }

        .info_header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-top: 60rpx;

            p {
                font-family: Manrope, Manrope;
                font-weight: bold;
                font-size: 36rpx;
                color: #1c120d;
                line-height: 46rpx;
            }

            text {
                font-size: 28rpx;
                color: #1c120d;
            }
        }

        ul {
            margin-top: 32rpx;

            li {
                display: flex;
                align-items: center;
                justify-content: space-between;
                margin-top: 24rpx;
                font-family: Manrope, Manrope;
                font-weight: 400;
                font-size: 28rpx;

                text {
                    display: inline-block;
                    color: #444444;
                }

                text:nth-child(2) {
                    color: #1c120d;
                }
            }
        }
    }

    .order_products {
        margin-top: 32rpx;

        .products_title {
            font-family: Manrope, Manrope;
            font-weight: bold;
            font-size: 36rpx;
            color: #1c120d;
            line-height: 46rpx;
            padding: 0 32rpx;
        }

        ul {
            margin-top: 14rpx;

            li {
                padding: 16rpx 36rpx;
                background: #fcfaf7;

                dl {
                    display: flex;

                    dt {
                        image {
                            width: 128rpx;
                            height: 128rpx;
                            background: #eee;
                            border-radius: 16rpx;
                        }
                    }

                    dd {
                        padding-left: 32rpx;
                        flex: 1;

                        .products_item {
                            display: flex;
                            align-items: center;
                            justify-content: space-between;
                            margin-bottom: 8rpx;

                            text {
                                display: inline-block;
                                font-weight: 400;
                                font-size: 28rpx;
                                color: #444444;
                            }

                            .line {
                                text-decoration: line-through;
                                color: #999;
                                display: inline-block;
                            }
                        }

                        .header {
                            text {
                                font-family: Manrope, Manrope;
                                font-weight: 500;
                                font-size: 32rpx;
                                color: #1c120d;
                                font-weight: bold;
                            }
                        }
                    }
                }
            }
        }
    }
}

.footer {
    width: 100%;
    position: fixed;
    bottom: 0;
    left: 0;
    background: #fff;
    padding: 32rpx 0;

    .footer_btn {
        height: 96rpx;
        border-radius: 50rpx;
        text-align: center;
        line-height: 96rpx;
        color: #fff;
        font-size: 32rpx;
        background: #fa751f;

        margin: 0 45rpx;
    }
}
</style>
